package riki.org.red5.acs.clients.applications.newxrussianbox;

import riki.org.red5.acs.clients.applications.newxrussianbox.datetype.player;
import riki.org.red5.acs.localdate.datetype.User;
import riki.org.red5.acs.utils.IO;

public class PlayerItem extends player
{
	public	boolean	canCreatedRoom		=	true;
	public	boolean	isOver				=	false;
	public	int		currentGameRoomId	=	-1;
	
	
	private	byte	maxpower			=	10;
	
	public PlayerItem(User u)
	{		
		this.playerId		= 	u.id.toString();
		this.imvuID			=	u.imvu_id;
		this.playerName		= 	u.imvu_name;
		this.playerNick		= 	u.imvu_nick;
		this.playerHeadImg	= 	u.imvu_face;
		this.isGirl			= 	u.imvu_isgirl;
		
		for(int i = 0 ; i < 200 ; i ++)
		{
			this.gameDate[i]=0;
		}
	}
	
	public void reInitPlayer()
	{
		this.isOver			=	false;
		this.playerScore	=	0;
		this.isBaoQi		=	false;
		this.gameDate		=	new int[200];
		this.canCreatedRoom = 	true;
		IO.traceln("reInitPlayer:"+this.playerId+this.canCreatedRoom);
		for(int i = 0 ; i < 200 ; i ++)
		{
			this.gameDate[i]=0;
		}
		this.power			=	0;
		this.isReady		=	false;
	}
	
	public void clearLine(byte lines,int[] cDate)
	{
		if(lines == 1)
		{
			power+=1;
			this.playerScore+=100;
		}
		if(lines == 2)
		{
			power+=3;
			this.playerScore+=300;
		}
		if(lines == 3)
		{
			power+=7;
			this.playerScore+=700;
		}
		if(lines == 4)
		{
			power+=15;
			this.playerScore+=1500;
		}
				
		int	count1		=	0;
		int	count2		=	0;
		
		for(int i = 0 ; i < 200 ; i ++)
		{
			if(this.gameDate[i]>0)
			{
				count1++;
			}
		}		
		
		for(int i = 0 ; i < 200 ; i ++)
		{
			if(cDate[i]>0)
			{
				count2++;
			}
		}
		
		count2=count2+lines*10;
		
		this.playerScore+=(count2-count1)*5;
		//IO.traceln("id:"+this.playerId+"  playerScore:"+playerScore);
		this.gameDate	=	cDate;
		
		this.isBaoQi = (power>=maxpower);
	}
	
	public boolean isAttack()
	{
		
		if(power>=maxpower)
		{
			power-=maxpower;
			this.isBaoQi = true;
			return true;
		}
		this.isBaoQi =	false;
		return false;
	}
	
	public boolean isOver()
	{
		for(int i = 0 ; i < 10 ; i ++)
		{
			if(this.gameDate[i]>0)
			{
				this.isOver	=	true;
				return true;
			}
		}
		this.isOver	=	false;
		return false;
	}
	
	public player toPlayer()
	{
		player returnPlayer				=	new player();
		returnPlayer.playerId			=	this.playerId;
		returnPlayer.imvuID				=	this.imvuID;
		returnPlayer.playerName			=	this.playerName;
		returnPlayer.playerNick			=	this.playerNick;
		returnPlayer.isGirl				=	this.isGirl;
		returnPlayer.isReady			=	this.isReady;
		returnPlayer.playerSeatId		=	this.playerSeatId;
		returnPlayer.currentGameRoomId	=	this.currentGameRoomId;
		returnPlayer.playerScore		=	this.playerScore;
		returnPlayer.gameDate			=	this.gameDate;
		returnPlayer.isBaoQi			=	this.isBaoQi;
		returnPlayer.power				=	this.power;
		returnPlayer.playerHeadImg		=	this.playerHeadImg;
		return returnPlayer;		
	}
}
